# the minimum version of CMake.
cmake_minimum_required(VERSION 3.5.0)
project(image-knife-c)

option(IMAGEKNIFEC_ENABLE_INSTALL "" ON)

set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})

if(DEFINED PACKAGE_FIND_FILE)
    include(${PACKAGE_FIND_FILE})
endif()

# Specify the C++ standard to use
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include_directories(${NATIVERENDER_ROOT_PATH}
                    ${NATIVERENDER_ROOT_PATH}/include
                    ${NATIVERENDER_ROOT_PATH}/include/data
                    ${NATIVERENDER_ROOT_PATH}/node
                    ${NATIVERENDER_ROOT_PATH}/cache
                    ${NATIVERENDER_ROOT_PATH}/interceptor
                    ${NATIVERENDER_ROOT_PATH}/thirdparty
                    ${NATIVERENDER_ROOT_PATH}/thirdparty/base64-0.5.2/include
                    ${NATIVERENDER_ROOT_PATH}/task
                    ${NATIVERENDER_ROOT_PATH}/utils
                    ${NATIVERENDER_ROOT_PATH}/data
                    ${NATIVERENDER_ROOT_PATH}/border
                    ${NATIVERENDER_ROOT_PATH}/key)

add_library(imageknifec SHARED napi_init.cpp
                        imageknife_napi.cpp
                        imageknife_internal.cpp
                        imageknife_dispatcher.cpp
                        request/imageknife_request_internal.cpp
                        task/imageknife_task_internal.cpp
                        task/task_worker.cpp
                        interceptor/interceptor.cpp
                        cache/memory_cache.cpp
                        key/default_cache_key_generator.cpp
                        cache/file_cache.cpp
                        loader/imageknife_loader.cpp
                        loader/imageknife_loader_internal.cpp
                        node/imageknife_node_internal.cpp
                        node/imageknife_node_animator.cpp
                        option/imageknife_option_napi.cpp
                        option/animator_option_napi.cpp
                        data/imageknife_data.cpp
                        data/onload_callback_napi.cpp
                        queue/default_job_queue.cpp
                        data/imageknife_data_napi.cpp
                        border/border_option_napi.cpp)

set(BASE64_WITH_NEON64 OFF CACHE BOOL "Disable NEON64 codepath in subproject")
add_subdirectory(${NATIVERENDER_ROOT_PATH}/thirdparty/base64-0.5.2)
if(TARGET base64)
    # 设置C++编译选项
    target_compile_options(base64 PRIVATE
        $<$<COMPILE_LANGUAGE:CXX>:-Wno-unused-command-line-argument>
    )

    # 设置C编译选项
    target_compile_options(base64 PRIVATE
        $<$<COMPILE_LANGUAGE:C>:-Wno-unused-command-line-argument>
    )
endif()

target_link_libraries(imageknifec PUBLIC libace_napi.z.so libace_ndk.z.so librcp_c.so
                             libimage_source.so libpixelmap.so librawfile.z.so libohresmgr.so libhilog_ndk.z.so
                             libohcrypto.so
                             libohfileuri.so
                             base64)

target_link_directories(imageknifec PUBLIC ${HMOS_SDK_NATIVE}/sysroot/usr/lib/aarch64-linux-ohos)

if (IMAGEKNIFEC_ENABLE_INSTALL)
set(IMAGEKNIFEC_INSTALL_PATH "${CMAKE_SOURCE_DIR}/../../../")
add_custom_command(TARGET imageknifec POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/include ${IMAGEKNIFEC_INSTALL_PATH}/include)
endif()
